package com.gary.security;

import org.springframework.security.GrantedAuthority;
import org.springframework.security.userdetails.User;
import org.springframework.security.userdetails.UserDetails;

import com.gary.security.model.UserInfo;


/**
 * 用户信息建造器.
 */
public class UserDetailsBuilder {
    /** protected constructor. */
    protected UserDetailsBuilder() {
    }

    /**
     * 使用参数生成一个用户对象.
     *
     * @param username String
     * @param password String
     * @param enabled boolean
     * @param auths Granted Authority
     * @return user details
     */
    public static UserDetails createUser(String username, String password,
        Integer status, GrantedAuthority[] auths) {
    	
        return new User(username, password, isEnabled(status), true, true, true,
            auths);
    }
    
    public static UserDetails createUser(String username, String password,
            boolean enable, GrantedAuthority[] auths) {
        	
            return new User(username, password, enable, true, true, true,
                auths);
        }
    
    private static boolean isEnabled(Integer status) {
        return ((status != null) && !status.equals(UserInfo.STATUS_DISABLED));
    }
}
